home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / batches / ls.bat < prev    next >
DOS Batch File  |  1993-10-30  |  3KB  |  114 lines

  1. @echo off
  2. !  ls.bat    Batch file to accept a UNIX-like ls command
  3. !
  4. !  Call ls as follows:
  5. !
  6. !         ls [opts] [rest]
  7. !
  8. !  where: opts  = a single argument which groups one or more of the following UNIX options:
  9. !                      -l list in long format
  10. !                      -t sort by time (latest first)
  11. !                      -a list all entries (including hidden files)
  12. !                      -r reverse order of sort (oldest first or reverse alphabetic)
  13. !                 Note that only one one initial dash is expected. That is, -at is ok,
  14. !                 while -a-t is not. Also "-a -t" is wrongly interpreted.
  15. !                 if 'opts' is missing, ls behaves like DIR.
  16. !         rest  = a series of up to 8 parameters like you would pass to DIR. This
  17. !                 includes the [wildcarded] file/folder name.
  18. !
  19. !  WARNING: if you interrupt the batch with CNTL-C, you might like to reset the system
  20. !           CMDDIR by typing "set dircmd=".
  21. !
  22. !  Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
  23. !
  24.  
  25. !set up the environment
  26. onerror ERR_LBL
  27. set FIRST=*
  28. set XT=0
  29. set XR=0
  30. set XDIRCMD=%DIRCMD%
  31. set DIRCMD=/-P/W/A:-HDXF/-O/-S/-B/-L
  32.  
  33. ! check the first parameter
  34. if "%1x" == x goto DODIR_LBL
  35. set XREST=%1x
  36. ! let's remove the first character (ie. the dash) from 'XREST'
  37. decr -XREST
  38. ! and now we remove the "dashless" first parameter from a full copy of it, so that
  39. ! we are left with the dash itself
  40. ! The 'y' is needed to prevent 'decr' from removing 'TMP' when the dash is not
  41. ! followed by any character.
  42. set TMP=y%1x
  43. decr TMP by %XREST%
  44. if not %TMP% == y- goto NOOPT_LBL
  45. ! check for the presence of something after the dash
  46. if %XREST% == x goto NOOPT_LBL
  47.  
  48. ! process one option at a time
  49. repeat OPT_LOOP_LBL
  50.  
  51.   ! isolate the first character
  52.   ! now 'XREST' contains at least the 'x' that we have appended to %1 when we created 'XREST'
  53.   set TMP=%XREST%
  54.   !let's remove the first character (ie. the option character) from 'XREST'
  55.   decr -XREST
  56.   ! here we do what we did to isolate the dash, but we do not need to prepend a 'y'
  57.   ! because we know that 'TMP' contains at least two characters and 'XREST' one
  58.   decr TMP by %XREST%
  59.   ! we are now ready to process the option character
  60.  
  61.   if not %TMP% == l goto END_L_LBL
  62.     set DIRCMD=%DIRCMD%/-w
  63.     goto NEXT_OPT_LBL
  64.   :END_L_LBL
  65.   if not %TMP% == t goto END_T_LBL
  66.     set XT=1
  67.     goto NEXT_OPT_LBL
  68.   :END_T_LBL
  69.   if not %TMP% == a goto END_A_LBL
  70.     set DIRCMD=%DIRCMD%/ah
  71.     goto NEXT_OPT_LBL
  72.   :END_A_LBL
  73.   if not %TMP% == r goto END_R_LBL
  74.     set XR=1
  75.     goto NEXT_OPT_LBL
  76.   :END_R_LBL
  77.   echo Invalid unix option (%TMP%). Valid options are: ltar
  78.   goto RET_LBL
  79.   :NEXT_OPT_LBL
  80.     if %XREST% == x goto BREAK_LBL
  81.   :OPT_LOOP_LBL
  82. :BREAK_LBL
  83.   if %XT% == 0 goto NO_XT_LBL
  84.     set TMP=-d
  85.     if %XR% == 1 set TMP=d
  86.     set DIRCMD=%DIRCMD%/o%TMP%
  87.     goto DODIR_LBL
  88.   :NO_XT_LBL
  89.     set TMP=n
  90.     if %XR% == 1 set TMP=-n
  91.     set DIRCMD=%DIRCMD%/o%TMP%
  92.     dir "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"
  93.     goto RET_LBL
  94.  
  95. :NOOPT_LBL
  96.   set FIRST=%1
  97.  
  98. :DODIR_LBL
  99.   dir "%FIRST%" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"
  100.   goto RET_LBL
  101.  
  102. :ERR_LBL
  103. show %DOSERR%
  104. onerror
  105.  
  106. :RET_LBL
  107. set DIRCMD=%XDIRCMD%
  108. set FIRST=
  109. set XT=
  110. set XR=
  111. set XDIRCMD=
  112. set XREST=
  113. set TMP=
  114.